﻿using SolidWorksTools;
using SwTools.Views;
using System;
using System.Runtime.InteropServices;
using Xarial.XCad.Base.Attributes;
using Xarial.XCad.UI.Commands;

namespace FirstSW
{
    [SwAddin(Description = "sldTest", LoadAtStartup = true, Title = "TestDemo")]
    [ComVisible(true)]
    [Title("swTools")]
    public class AddinStudy : Xarial.XCad.SolidWorks.SwAddInEx
    {
        public override void OnConnect()
        {
            Application.ShowMessageBox("Hello xCAD");
            CommandManager.AddCommandGroup<SwCommand>().CommandClick += AddinStudy_CommandClick; 
            CreateTaskPane();

        }

        private void AddinStudy_CommandClick(SwCommand spec) 
        {
            switch (spec) 
            {
                case SwCommand.Com1:
                    //窗口
                    var window = new TestWindow(Application.WindowHandle);  //传入sw的句柄 
                    window.Show();
                    break;
                case SwCommand.AddModelViewTap:
                    AddModelViewTab();
                    break;
                case SwCommand.AddFeatureManagerTap:
                    AddFeatureManagerTap();
                    break;
                default:
                    break;
            }
        }

        private void AddModelViewTab()
        {
            var activeDoc = Application.Documents.Active;
            if (activeDoc == null)
            {
                return;
            }
            var featureMgrTab = CreateDocumentTab<ModelViewTab>(activeDoc);  //窗口
            featureMgrTab.Control.Sw = Application.Sw;
        }

        private void AddFeatureManagerTap()
        {
            var activeDoc = Application.Documents.Active;
            if (activeDoc == null)
            {
                return;
            }
            var featureMgrTab = CreateFeatureManagerTab<FeatureManagerTab>(activeDoc);  //窗口
            featureMgrTab.Control.Sw = Application.Sw;
        }

        private void CreateTaskPane()
        {
            var swTaskPane = this.CreateTaskPane<TaskPanel>();  //窗口
            swTaskPane.Control.Sw = Application.Sw;
        }


        public override void OnDisconnect()
        {
            Application.ShowMessageBox("Hello xCAD Close?");
        }

    }
}
